package com.six.firstpage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.six.core.entity.Banner;
import com.six.firstpage.service.BannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.jacoco.agent.rt.RT;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.yaml.snakeyaml.events.Event;

/**
 * @author:zzh
 * @create: 2023-02-28 11:12
 * @Description:
 */
@Api(value = "/firstpage/banner", tags = {"轮播图后台接口"})
@RestController
@RequestMapping("/firstpage/banner")
public class BannerController {

    @Autowired
    private BannerService bannerService;

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "title", value = "", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "status", value = "", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "current", value = "", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "", required = false)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("getBannerByTitle/{current}/{pageSize}")
    public Page<Banner> getBannerByTitle(String title, @RequestParam(defaultValue = "0") Integer status, @PathVariable @RequestParam(defaultValue = "1") Integer current, @PathVariable  @RequestParam(defaultValue = "5") Integer pageSize){
        return bannerService.getBannerByTitle(title,status,current,pageSize);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Banner", name = "banner", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("addBanner")
    public Integer addBanner(@RequestBody Banner banner){
        return bannerService.addBanner(banner);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Banner", name = "banner", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "PUT")
    @PutMapping("updateBanner")
    public Integer updateBanner(@RequestBody Banner banner){
        return bannerService.updateBanner(banner);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("/delBanner/{id}")
    public Integer delBanner(@PathVariable Integer id){
        return bannerService.delBanner(id);
    }
}
